package com.renli.service.impl;

import com.renli.bean.ResultJson;
import com.renli.mapper.*;
import com.renli.service.LoginService;
import com.renli.service.RoleService;
import com.renli.service.UserUpdateVoService;
import com.renli.vo.UserUpdateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserUpdateVoServiceImpl implements UserUpdateVoService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private ArchivesMapper archivesMapper;
    @Autowired
    private LoginMapper loginMapper;
    @Autowired
    private RoleMapper roleMapper;


    /**
     * 系统管理 修改用户
     *
     * @param vo
     * @return
     */
    @Override
    public boolean update(UserUpdateVo vo) {


        String phone = vo.getPhone();
//        跟新用户名和密码
        loginMapper.updateUP(vo);
        //更新角色
        userMapper.update(vo);
        //更新电话
        archivesMapper.updatePhone(vo);


        return false;
    }

    /**
     * 查询用户信息
     *
     * @param vo
     * @return
     */
    @Override
    public ResultJson<List<UserUpdateVo>> find(UserUpdateVo vo) {

        ResultJson<List<UserUpdateVo>> resultJson = new ResultJson<>();

        if (vo.getCurrentPage()==null){
            vo.setCurrentPage(1);
        }
        if (vo.getLimit() == null){
            vo.setLimit(6);
        }
        Long count = userMapper.selectCount(vo);

        List<UserUpdateVo> list = userMapper.select(vo);
        resultJson.setSuccess("执行了查询",list,count);
        return resultJson;

    }
}
